package cn.tsa.share.jdbc.service;

import cn.tsa.share.jdbc.domain.Order;
import cn.tsa.share.jdbc.domain.OrderItem;
import cn.tsa.share.jdbc.domain.OrderQuery;
import cn.tsa.share.jdbc.repository.OrderItemRepository;
import cn.tsa.share.jdbc.repository.OrderRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class OrderService  {

	private final OrderRepository orderRepository;

	private final OrderItemRepository orderItemRepository;

	public Long saveOrder(Order order) {
		orderRepository.insert(order);
		return order.getOrderId();
	}

	public Long addOrder(Order order) {
		orderRepository.insert(order);
		OrderItem orderItem=new OrderItem();
		orderItem.setOrderId(order.getOrderId());
		orderItem.setUserId(order.getUserId());
		orderItemRepository.insert(orderItem);
		return order.getOrderId();
	}

    public List<Order> searchAllList(OrderQuery orderQuery) {
		return orderRepository.searchAllList(orderQuery);
    }
}
